import { createRequestInstance, createEnhancedFetch } from '@/utils/request'
import { getAuthConfig } from '@/config/auth.config'

const authConfig = getAuthConfig()

// 创建客户端的axios实例
const service = createRequestInstance({
  baseURL: window.__APP_CONFIG?.BASE_URL,
  timeout: window.__APP_CONFIG?.TIMEOUT,
  isClient: true,
  useElementUI: false, // 客户端可能不使用Element UI
  redirectPath: authConfig.CLIENT_LOGIN_PATH,
  tokenKey: authConfig.TOKEN_KEY,
  autoLogoutTime: authConfig.AUTO_LOGOUT_TIME,
  debug: authConfig.DEBUG_ENABLED,
  verifyTokenURL: authConfig.VERIFY_TOKEN_URL,
  setupActivityMonitor: false, // 禁用客户端的活动监听器，由管理端统一监听
})

// 创建客户端的enhancedFetch
export const enhancedFetch = createEnhancedFetch({
  baseURL: window.__APP_CONFIG?.BASE_URL,
  timeout: window.__APP_CONFIG?.TIMEOUT,
  isClient: true,
  redirectPath: authConfig.CLIENT_LOGIN_PATH,
  debug: authConfig.DEBUG_ENABLED,
})

export default service
